<?php
/**
 * Aero - Xistins Technologies PHP Framework
 * 
 * LICENSE
 * This source file is subject to the New BSD license that is bundled 
 * with this package in the LICENSE.txt. It is also available through 
 * the world-wide-web at this URL: http://dev.xistins.com/license/production
 * If you did not receive a copy of this license and are unable to obtain
 * it through the world-wide-web, please send an email to 
 * license@xistins.com so we can send you a copy immediately.
 * 
 * @category   Aero
 * @package    Aero_Db
 * @subpackage Statement
 * @copyright  http://dev.xistins.com/license/production     New BSD
 * @version    $Id: Statement.php 4 2009-11-14 18:35:45Z csouth@xistins.com $
 */

/**
 * Base database adapter class
 * 
 * @category   Aero
 * @package    Aero_Db
 * @subpackage Statement
 * @copyright  http://dev.xistins.com/license/production     New BSD
 * @version    $Id: Statement.php 4 2009-11-14 18:35:45Z csouth@xistins.com $
 */
class Aero_Db_Statement
{
    /**
     * Database Adapter
     * @var Aero_Db_Adapter
     */
    protected $_db;

    /**
     * SQL Query
     * @var string
     */
    protected $_sql;

    /**
     * Statement Constructor
     * 
     * @param  string $sql
     * @param  Aero_Db_Adapter $adapter
     * @return void
     */
    public function __construct($sql, $adapter)
    {
        $this->_sql = $sql;
        $this->_db  = $adapter;
    }

    /**
     * Run a query with added variables
     * 
     * @return array|bool
     */
    public function execute()
    {
        $args = func_get_args();

        foreach($args as $arg) {
            $replacement = $this->_db->escape($arg);
            $this->_sql = preg_replace('/\?/', $replacement, $this->_sql, 1);
        }

        return $this->_db->query($this->_sql);
    }
}